  <?php 
    header("Content-type: text/html; charset=UTF-8"); 
    
    //文件路径 ，mimetype ，上传文件定义的名字
    $cFile = curl_file_create('./test.png','image/png','test2.png');
    // echo $cFile -> getPostFilename();
    //php7.0开始用CURLFile
    // $cFile = new CURLFile('./test.png','image/png','test1.png');
    
    $curl = curl_init();

 
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   
   // 设置header 响应头是否输出
   curl_setopt($curl, CURLOPT_HEADER, 0);
   // 设置你需要抓取的URL
   curl_setopt($curl, CURLOPT_URL, "http://localhost/php/form/file_upload.php");

   //TRUE 时会发送 POST 请求，类型为：application/x-www-form-urlencoded，是 HTML 表单提交时最常见的一种
   curl_setopt($curl, CURLOPT_POST, 1);
   
   curl_setopt($curl, CURLOPT_SAFE_UPLOAD, 1);
   
   //设置头信息
   curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);

   //以post的键名链接cFile
   curl_setopt($curl, CURLOPT_POSTFIELDS, ["file"=>$cFile,"p1"=>'aaaa','p2'=>'bbbbb']);

   $result = curl_exec($curl); 
   curl_close($curl);
   var_dump($result);
 ?>